package com.lh_travel.lohas.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.transition.Explode;
import android.transition.TransitionManager;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.lh_travel.lohas.R;
import com.lh_travel.lohas.adapter.BaseRecyclerHolder;
import com.lh_travel.lohas.adapter.SwitchRecylerAdapter;
import com.lh_travel.lohas.base.api;
import com.lh_travel.lohas.base.baseActivity;
import com.lh_travel.lohas.domain.CommentIntentBean;
import com.lh_travel.lohas.domain.DafultMessageEvent;
import com.lh_travel.lohas.domain.FilterMessage;
import com.lh_travel.lohas.domain.HotelFilterBean;
import com.lh_travel.lohas.domain.HotelListBean;
import com.lh_travel.lohas.utils.ImageUtils;
import com.lh_travel.lohas.utils.MapUtil;
import com.lh_travel.lohas.utils.PhotoUtil;
import com.lh_travel.lohas.utils.Preferences;
import com.lh_travel.lohas.widget.DefineLoadMoreView;
import com.tamic.novate.Throwable;
import com.tamic.novate.callback.RxResultCallback;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;

/**
 * Created by aaron on 2018/6/14.
 */

public class HotelListActivity extends baseActivity {
    /*筛选条件*/
    private int count = 10;
    private int page = 1;

    private String order_type = "0";
    private String sore_type = "";
    private String price_type = "";
    private String star_type = "";
    private String theme_type = "";
    private String device_type = "";
    private String position_type = "";

    //recycle标志位
    public int actionType;
    public final int finish = 0;
    public final int INIT = 1;
    public final int LOADMORE = 2;

    private Switch switchs;
    private RadioButton rb_discount;
    private RadioButton rb_price;
    private RadioButton rb_score;
    private TextView tv_filter_result;
    private SwipeMenuRecyclerView rv_swipe;
    private ArrayList<HotelListBean.SimpleHotelBean> hotel_list = new ArrayList<>();
    private SwitchRecylerAdapter switchAdapter;
    private LinearLayout ll_foot;
    private LinearLayout ll_filter;
    private LinearLayout ll_map;

    private String belong;
    private String keyword;
    private String lat;
    private String lng;

    private String checkIn;
    private String checkOut;
    private TextView tv_keyword;
    private RelativeLayout rl_keyword;
    private CommentIntentBean detailBean;
    private TextView tv_date;
    private HotelFilterBean filterBean;
    private int tempPisition;
    private Button btn_main;
    private ImageButton img_back;
    private boolean first = true;
    private RadioGroup rg_group;
    private boolean isLoadDate = false;

    @SuppressLint("HandlerLeak")
    private Handler uiHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {

                case 1:

                    isLoadDate = true;

                    new api(mContext).getHotelList(checkIn, checkOut, belong, count, page, keyword, order_type, lat, lng,
                            sore_type, price_type, star_type, theme_type, device_type, position_type, hotelistCallBack);

                    break;

                case 2:

                    String s = (String) msg.obj;
                    tv_keyword.setText(s);

                    page = 1;
                    actionType = INIT;

                    isLoadDate = true;

                    new api(mContext).getHotelList(checkIn, checkOut, belong, count, page, keyword, order_type, lat, lng,
                            sore_type, price_type, star_type, theme_type, device_type, position_type, hotelistCallBack);

                    new api(mContext).getConditions(keyword, conditionCallBack);
                    break;

                case 3:

                    tv_keyword.setText("我的附近");

                    page = 1;
                    actionType = INIT;

                    isLoadDate = true;

                    new api(mContext).getHotelList(checkIn, checkOut, belong, count, page, keyword, order_type, lat, lng,
                            sore_type, price_type, star_type, theme_type, device_type, position_type, hotelistCallBack);

                    new api(mContext).getConditions(mApp.getPreference(Preferences.LOCAL.CITY), conditionCallBack);
                    break;
            }

        }
    };
    private SwipeMenuRecyclerView.LoadMoreListener mLoadMoreListener;
    private boolean is_empty;
    private boolean has_more;
    private int totoal;
    private LinearLayout ll_switch;

    @Override
    protected void onResume() {
        super.onResume();

        if (isLoadDate)
        showViewLoad();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        EventBus.getDefault().register(this);

        setContentView(R.layout.activity_hotellist);

        findView();
        bindListner();
        ensureUI();
    }

    @Override
    public void findView() {
        rv_swipe = (SwipeMenuRecyclerView) findViewById(R.id.rv_swipe);
        switchs = (Switch) findViewById(R.id.switchs);
        ll_foot = (LinearLayout) findViewById(R.id.ll_foot);
        ll_filter = (LinearLayout) findViewById(R.id.ll_filter);
        ll_map = (LinearLayout) findViewById(R.id.ll_map);
        tv_keyword = (TextView) findViewById(R.id.tv_keyword);
        rl_keyword = (RelativeLayout) findViewById(R.id.rl_keyword);
        tv_date = (TextView) findViewById(R.id.tv_date);
        btn_main = (Button) findViewById(R.id.btn_main);

        tv_filter_result = (TextView) findViewById(R.id.tv_filter_result);
        rg_group = (RadioGroup) findViewById(R.id.rg_group);

        rb_discount = (RadioButton) findViewById(R.id.rb_discount);
        rb_price = (RadioButton) findViewById(R.id.rb_price);
        rb_score = (RadioButton) findViewById(R.id.rb_score);
        img_back = (ImageButton) findViewById(R.id.img_back);
        ll_switch = (LinearLayout) findViewById(R.id.ll_switch);
    }


    @Override
    public void bindListner() {

        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mApp.path = null;
                finish();
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

            }
        });

        switchs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                switchAdapter.switchLayout(!switchAdapter.show);
            }
        });

        ll_map.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (hotel_list.size() > 0) {

                    Intent intent = new Intent(mContext, HotelMapActivity.class);

                    CommentIntentBean bean = new CommentIntentBean();

                    bean.keyWord = keyword;
                    bean.checkIn = checkIn;
                    bean.checkOut = checkOut;
                    bean.lat = hotel_list.get(0).lat;
                    bean.lng = hotel_list.get(0).lng;

                    intent.putExtra("detail", bean);

                    startActivity(intent);

                } else {

                    showMessage(mContext.getString(R.string.listempty));
                }

            }
        });

        rb_discount.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    rv_swipe.loadMoreFinish(false, true);

                    page = 1;
                    order_type = "0";
                    actionType = INIT;

                    //  rvExpose();
                    showViewLoad();
                    new api(mContext).getHotelList(checkIn, checkOut, belong, count, page, keyword, order_type, lat, lng,
                            sore_type, price_type, star_type, theme_type, device_type, position_type, hotelistCallBack);
                    footGone();
                }
            }
        });

        rb_price.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    rv_swipe.loadMoreFinish(false, true);

                    page = 1;
                    order_type = "3";
                    actionType = INIT;

                    // rvExpose();
                    showViewLoad();
                    new api(mContext).getHotelList(checkIn, checkOut, belong, count, page, keyword, order_type, lat, lng,
                            sore_type, price_type, star_type, theme_type, device_type, position_type, hotelistCallBack);
                    footGone();
                }
            }
        });

        rb_score.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked) {
                    rv_swipe.loadMoreFinish(false, true);

                    page = 1;
                    order_type = "4";
                    actionType = INIT;

                    //  rvExpose();
                    showViewLoad();
                    new api(mContext).getHotelList(checkIn, checkOut, belong, count, page, keyword, order_type, lat, lng,
                            sore_type, price_type, star_type, theme_type, device_type, position_type, hotelistCallBack);
                    footGone();
                }
            }
        });

        ll_filter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (filterBean != null){

                    Intent intent = new Intent(mContext, HotelFilterActivity.class);

                    intent.putExtra("detail", filterBean);

                    startActivity(intent);

                }else {

                    showMessage("请搜索有意义的关键字");
                }

            }
        });

        rl_keyword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivity(new Intent(mContext, ContentSearchActivity.class));

            }
        });

        tv_date.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, CalendarActivity.class);
                intent.putExtra("mutil", true);

                intent.putExtra("checkIn", checkIn);
                intent.putExtra("checkOut", checkOut);

                mContext.startActivity(intent);
            }
        });

        btn_main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(mContext, HomeActivity.class);

                Bitmap bit = PhotoUtil.takeScreenShot(HotelListActivity.this);

                mApp.path = ImageUtils.compressImage(bit, "lhshot", 1000);

                startActivity(intent);

                overridePendingTransition(0, 0);

            }
        });
    }

    @Override
    public void ensureUI() {

        actionType = INIT;

        if (mApp.getPreference(Preferences.LOCAL.COUNTRY).equals("cn")) {

            //转换成百度地图
            // lat = MapUtil.gcj02_To_Bd09()

            Double latDouble = Double.valueOf(mApp.getPreference(Preferences.LOCAL.LAT));
            Double lngDouble = Double.valueOf(mApp.getPreference(Preferences.LOCAL.LNG));

            lat = MapUtil.gcj02_To_Bd09(latDouble, lngDouble)[0] + "";
            lng = MapUtil.gcj02_To_Bd09(latDouble, lngDouble)[1] + "";

        } else {

            lat = mApp.getPreference(Preferences.LOCAL.LAT);
            lng = mApp.getPreference(Preferences.LOCAL.LNG);

        }

        belong = mApp.getPreference(Preferences.LOCAL.COUNTRY);

        detailBean = (CommentIntentBean) getIntent().getSerializableExtra("detail");
        is_empty = getIntent().getBooleanExtra("empty", false);

        if (is_empty){
            //没有数据

        }else {

            //有数据
            hotel_list = (ArrayList<HotelListBean.SimpleHotelBean>) getIntent().getSerializableExtra("list");
            has_more = getIntent().getBooleanExtra("hasmore", false);
            totoal = getIntent().getIntExtra("totoal", 0);
        }

        keyword = detailBean.keyWord;

        checkIn = detailBean.checkIn;

        checkOut = detailBean.checkOut;

        tv_keyword.setText(keyword.equals("") ? "我的附近" : keyword);

        tv_date.setText(checkIn.substring(5).replace("-", ".") + "-" + checkOut.substring(5).replace("-", "."));

        initXrv();

        new api(mContext).getConditions(keyword.equals("") ? mApp.getPreference(Preferences.LOCAL.CITY) : keyword, conditionCallBack);

    }

    private void footGone() {

        if (switchAdapter != null) {

            TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
                    0, Animation.RELATIVE_TO_SELF, 0,
                    Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1);

            translateAnimation.setDuration(500);

            ll_foot.startAnimation(translateAnimation);

            ll_foot.setVisibility(View.GONE);
        }
    }

    private void footVisable(boolean switchsVisable, String text) {

        TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
                0, Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0);

        translateAnimation.setStartOffset(300);
        translateAnimation.setDuration(600);

        ll_foot.startAnimation(translateAnimation);

        ll_foot.setVisibility(View.VISIBLE);
        ll_switch.setVisibility(switchsVisable ? View.VISIBLE : View.GONE);
        tv_filter_result.setText(text);
    }

    private void rvExpose() {

        for (int i = 0; i < rg_group.getChildCount(); i++) {
            rg_group.getChildAt(i).setEnabled(false);
        }

        if (switchAdapter != null) {

            Explode explode = new Explode();
            explode.setDuration(500);
            TransitionManager.beginDelayedTransition(rv_swipe, explode);

            rv_swipe.setAdapter(null);

        }
        showViewLoad();
        new api(mContext).getHotelList(checkIn, checkOut, belong, count, page, keyword, order_type, lat, lng,
                sore_type, price_type, star_type, theme_type, device_type, position_type, hotelistCallBack);

    }

    private RxResultCallback<HotelFilterBean> conditionCallBack = new RxResultCallback<HotelFilterBean>() {
        @Override
        public void onNext(Object tag, int code, String message, HotelFilterBean response) {

            if (code == 200){

                filterBean = response;
                filterBean.id = "HotelListActivity";
            }else {

                filterBean = null;
            }

        }

        @Override
        public void onError(Object tag, Throwable e) {

        }

        @Override
        public void onCancel(Object tag, Throwable e) {

        }
    };

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        mApp.path = null;
        finish();
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }

    private RxResultCallback<HotelListBean> hotelistCallBack = new RxResultCallback<HotelListBean>() {
        @Override
        public void onNext(Object tag, int code, String message, HotelListBean response) {

            dismissViewLoad();
            isLoadDate = false;

            for (int i = 0; i < rg_group.getChildCount(); i++) {
                rg_group.getChildAt(i).setEnabled(true);
            }

            switch (actionType) {

                case INIT:

                    if (code == 200) {

                        if (switchAdapter != null) {

                            switchAdapter = null;
                            hotel_list.clear();
                        }

                        hotel_list.addAll(response.hotel_list);
                        initXrv();

                        if (hotel_list.size() < response.total_count) {
                            rv_swipe.loadMoreFinish(false, true);

                        } else {
                            rv_swipe.loadMoreFinish(false, false);

                        }

                        footVisable(true, "筛选结果 共" + response.total_count + "家酒店");

                    } else if (code == 101 || code == 401) {

                        if (switchAdapter == null) {

                            initXrv();
                            rv_swipe.loadMoreFinish(true, true);

                        } else {

                            hotel_list.clear();
                            switchAdapter.notifyDataSetChanged();
                            rv_swipe.loadMoreFinish(true, false);
                        }
                        footVisable(false, "筛选结果 共0家酒店");
                    }

                    break;

                case LOADMORE:

                    hotel_list.addAll(response.hotel_list);
                    switchAdapter.notifyDataSetChanged();

                    if (hotel_list.size() == response.total_count) {

                        rv_swipe.loadMoreFinish(false, false);

                    } else {

                        rv_swipe.loadMoreFinish(false, true);
                    }

                    break;
            }
            actionType = finish;
        }

        @Override
        public void onError(Object tag, Throwable e) {
            dismissViewLoad();
            for (int i = 0; i < rg_group.getChildCount(); i++) {
                rg_group.getChildAt(i).setEnabled(true);
            }

            if (switchAdapter != null) {
                rv_swipe.loadMoreFinish(false, true);
            }
        }

        @Override
        public void onCancel(Object tag, Throwable e) {
            dismissViewLoad();
            for (int i = 0; i < rg_group.getChildCount(); i++) {
                rg_group.getChildAt(i).setEnabled(true);
            }
        }
    };

    private void initXrv() {

        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);

        rv_swipe.setLayoutManager(layoutManager);

        switchAdapter = new SwitchRecylerAdapter<HotelListBean.SimpleHotelBean>(mContext, rv_swipe, hotel_list,
                R.layout.item_hotellist_1, R.layout.item_hotel_list_2, true, switchs.isChecked()) {

            @Override
            public void convert(BaseRecyclerHolder holder, final HotelListBean.SimpleHotelBean item, int position, int layoutType) {

                switch (layoutType) {
                    case SwitchRecylerAdapter.COMMENT_FIRST:

                        //图片
                        holder.setImageByUrl(R.id.img_pic, item.picture + "?x-oss-process=image/resize,p_30", R.drawable.default_bg200x200);

                        break;

                    case SwitchRecylerAdapter.COMMENT_SECOND:

                        holder.setImageByUrl(R.id.img_pic, item.picture, R.drawable.default_bg640x320);

                        break;
                }

                LinearLayout container = holder.getView(R.id.ll_star_container);

                switch (item.star) {
                    case "豪华":

                        setStar(5, container);

                        break;

                    case "高档":

                        setStar(4, container);

                        break;

                    case "舒适":

                        setStar(3, container);

                        break;

                    case "经济":

                        setStar(2, container);

                        break;
                }

                //距离
                holder.setText(R.id.tv_distent, item.distance + "km");

                //酒店名称
                holder.setText(R.id.tv_name, item.title);

                //地标
                holder.setText(R.id.tv_position, "距离" + item.position_name + item.pos_distance + "km");

                //评分

                if (!item.fake_comment.equals("暂无评论")){
                    holder.setText(R.id.tv_comment, item.fake_comment + item.fake_comment_score + "/" + item.fake_comment_num + "评论");

                }else {
                    holder.setText(R.id.tv_comment, item.fake_comment);
                }

                //价格
                holder.setText(R.id.tv_discount_price, "¥" + item.min_price);

                if (item.min_price.equals("满房")){
                    //原价
                    holder.setText(R.id.tv_discount_price, "已满房");
                    holder.setViewsVisable(R.id.tv_ori_price, false);

                }else {
                    //价格
                    holder.setText(R.id.tv_discount_price, "¥" + item.min_price);
                    holder.setText(R.id.tv_ori_price, "¥" + item.max_price);
                    holder.setTextFlag(R.id.tv_ori_price, 1);
                    holder.setViewsVisable(R.id.tv_ori_price, true);
                }

                //优惠
                double value = new BigDecimal(item.rate).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

                if (value > 0.4) {
                    holder.setText(R.id.tv_discount, "优惠" + ((int) (value * 100)) + "%" + "\n 仅限今天");
                    holder.setViewsVisable(R.id.tv_discount, true);

                } else if (value > 0.1) {
                    holder.setText(R.id.tv_discount, "优惠" + ((int) (value * 100)) + "%");
                    holder.setViewsVisable(R.id.tv_discount, true);

                } else {
                    holder.setViewsVisable(R.id.tv_discount, false);
                }

                final ImageView img = holder.getView(R.id.img_pic);
                final TextView name = holder.getView(R.id.tv_name);

                holder.setViewClickLisenter(R.id.main, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(mContext, HotelDetailActivity.class);

                        CommentIntentBean bean = new CommentIntentBean();

                        bean.belong = item.belong;
                        bean.id = item.id;
                        bean.checkIn = checkIn;
                        bean.checkOut = checkOut;
                        bean.keyWord = item.title;
                        intent.putExtra("detail", bean);
                        intent.putExtra("star", item.star);

                        mContext.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation((Activity) mContext,
                                /*new Pair<View, String>(img, "TRANSITIONIMAGE"),*/ new Pair<View, String>(name, "TRANSITIONTITLE")).toBundle());
                    }
                });
            }

            @Override
            public void setAnimation(View viewToAnimate, int position) {

                Animation animation = null;

                RecyclerView.LayoutManager layoutManager = rv_swipe.getLayoutManager();

                LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
                int firstVisibleItemPosition = linearManager.findFirstVisibleItemPosition();
                int lastVisibleItemPosition = linearManager.findLastCompletelyVisibleItemPosition();

                if (lastVisibleItemPosition > firstVisibleItemPosition && tempPisition != firstVisibleItemPosition) {

                    if (position > lastVisibleItemPosition) {

                        animation = AnimationUtils.loadAnimation(viewToAnimate.getContext(), R.anim.fd);

                    } else if (position < firstVisibleItemPosition) {

                        animation = AnimationUtils.loadAnimation(viewToAnimate.getContext(), R.anim.sx);
                    }

                    if (animation != null) {

                        tempPisition = firstVisibleItemPosition;

                        if ((lastVisibleItemPosition - firstVisibleItemPosition) > 1) {

                            animation.setInterpolator(new AccelerateDecelerateInterpolator());
                            viewToAnimate.startAnimation(animation);

                        }

                    }

                }
            }
        };

        mLoadMoreListener = new SwipeMenuRecyclerView.LoadMoreListener() {
            @Override
            public void onLoadMore() {

                page++;
                actionType = LOADMORE;

                new api(mContext).getHotelList(checkIn, checkOut, belong, count, page, keyword, order_type, lat, lng,
                        sore_type, price_type, star_type, theme_type, device_type, position_type, hotelistCallBack);

            }
        };

        if (first) {
            DefineLoadMoreView loadMoreView = new DefineLoadMoreView(this);
            rv_swipe.addFooterView(loadMoreView); // 添加为Footer。
            rv_swipe.setLoadMoreView(loadMoreView); // 设置LoadMoreView更新监听。
            rv_swipe.setLoadMoreListener(mLoadMoreListener); // 加载更多的监听。

            if (is_empty){
                footVisable(false, "筛选结果 共 0 家酒店");
                rv_swipe.loadMoreFinish(true, false);

            }else {

                footVisable(true, "筛选结果 共 " + totoal + " 家酒店");
                rv_swipe.loadMoreFinish(false, has_more ? true : false);
            }

            first = false;
        }

      /*  Explode explode = new Explode();
        explode.setDuration(200);
        TransitionManager.beginDelayedTransition(rv_swipe, explode);*/

        rv_swipe.setAutoLoadMore(true);
        rv_swipe.setAdapter(switchAdapter);
    }

    private void setStar(int count, LinearLayout container) {

        container.removeAllViews();

        for (int i = 0; i < count; i++) {

            View view = View.inflate(mContext, R.layout.item_stars, null);

            ImageView img_star = view.findViewById(R.id.img_star);

            img_star.setImageResource(R.drawable.star);

            container.addView(view);

        }
    }

    private void resetFilter(){
        order_type = "";
        sore_type = "";
        price_type = "";
        star_type = "";
        theme_type = "";
        device_type = "";
        position_type = "";
    }

    //日期回调
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void handleMessageEvent(DafultMessageEvent message) {
        switch (message.TAG) {

            case "CalendarActivity":

                checkIn = message.checkin;
                checkOut = message.checkout;

                tv_date.setText(checkIn.substring(5).replace("-", ".") + "-" + checkOut.substring(5).replace("-", "."));

                page = 1;
                actionType = INIT;

                Message msg = uiHandler.obtainMessage();
                msg.what = 1;
                uiHandler.sendMessage(msg);

                break;
        }
    }

    //城市回调
    @Subscribe(threadMode = ThreadMode.ASYNC)
    public void backMessageEvent(DafultMessageEvent message) {
        Message msg = uiHandler.obtainMessage();

        switch (message.TAG) {
            case "ContentSearchActivity":

                belong = message.belong;
                keyword = message.message;

                resetFilter();

                msg.obj = keyword;
                msg.what = 2;

                mApp.setListPrefernce(Preferences.LOCAL.SEARCH_KEYWORD, keyword, belong);

                uiHandler.sendMessage(msg);
                break;

            case "ContentSearchActivity2":

                belong = message.belong;
                keyword = "";

                msg.what = 3;

                resetFilter();

                mApp.setListPrefernce(Preferences.LOCAL.SEARCH_KEYWORD, "我的附近", belong);

                uiHandler.sendMessage(msg);
                break;
        }
    }

    //筛选回调
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void filterMessageEvent(FilterMessage message) {
        switch (message.TAG) {

            case "HotelListActivity":

                sore_type = message.scorePostion;
                price_type = message.pricePostion;
                star_type = message.starPostion;
                theme_type = message.themePostion;
                position_type = message.position;

                filterBean = message.bean;

                page = 1;
                actionType = INIT;

                Message msg = uiHandler.obtainMessage();
                msg.what = 1;
                uiHandler.sendMessage(msg);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
        uiHandler.removeCallbacksAndMessages(null);
    }

}
